<template>
<!-- vue3组件中的模板结构可以没有根标签div -->
  <h1>一个人的信息</h1>
  <h2>姓：<input type="text" v-model="person.firstName" ></h2>
  <h2>名：<input type="text" v-model="person.lastName" ></h2>
  <!-- <slot> </slot> -->
  <br>
  <span>全名：<input type="text" v-model="person.fullName" ></span>
</template>

<script>
import {reactive ,computed} from 'vue'

export default {
  name: 'App',
//   computed:{
//       fullName(){
//           return this.person.firstName + '-' + this.person.lastName
//       }
//   },
  setup() {
    // Data
      let person = reactive({
        firstName:'张',
        lastName:'三',
      })
    //   计算属性 简写(没有考虑被修改的情况)
    //  person.fullName = computed(()=>{
    //     return person.firstName + '-' + person.lastName
    // })
    // 完整
    person.fullName = computed({
        get(){
            return person.firstName + '-' + person.lastName
        },
        set(value){
            const nameArr = value.split('-')
            person.firstName = nameArr[0]
            person.lastName = nameArr[1]
        }
    })
    
      return {
        person,
      }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
